﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.MapInfo.BLL;
using Yipusoft.MapInfo.Model;

public partial class BasicBase_SoldierArchive_SoldierView1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Yipusoft.MapInfo.BLL.Cadre soldier = new Yipusoft.MapInfo.BLL.Cadre();
            SoldierArchiveInfo soldierInfo = soldier.GetSoldierInfoByID(Request["ID"]);
            //bool enableViewed = false;
            //string AccountDepartmentID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
            //if (Yipusoft.Account.BLL.User.HasPermission(Context.User.Identity.Name, "203001"))
            //{
            //    enableViewed = true;
            //}
            //else
            //{
            //    if ((Yipusoft.Account.BLL.User.HasPermission(Context.User.Identity.Name, "203006")))
            //        enableViewed = AccountDepartmentID.Substring(0, 4) == soldierInfo.DepartmentID.Substring(0, 4);
            //    else
            //        enableViewed = AccountDepartmentID == soldierInfo.DepartmentID;
            //}
            //if (enableViewed)
            //{
                //lblTitle.Text = "兵员详细信息";
                SoldierName.Text = soldierInfo.CadreName;
               
                Sex.Text = soldierInfo.Sex;
                imgPhoto.ImageUrl = soldierInfo.Picture == "" ? "~/Images/NoPhoto.png" :  soldierInfo.Picture;
                NativeName.Text = soldierInfo.NativeName;
                NationName.Text = soldierInfo.NationName;
                BackgroundName.Text = soldierInfo.BackgroundName;
                Marriage.Text = soldierInfo.Marriage;
                CultureName.Text = soldierInfo.CultureName;
                ReligionName.Text = soldierInfo.ReligionName;
                DepartmentName.Text = soldierInfo.DepartmentName;
                Birthday.Text = soldierInfo.Birthday.Year == 9999 ? "--" : soldierInfo.Birthday.ToString("yyyy-MM-dd");
                JoinDate.Text = soldierInfo.Birthday.Year == 9999 ? "--" : soldierInfo.JoinTime.ToString("yyyy-MM-dd");
                YouthDate.Text = soldierInfo.Birthday.Year == 9999 ? "--" : soldierInfo.YouthTime.ToString("yyyy-MM-dd");
                PartyDate.Text = soldierInfo.Birthday.Year == 9999 ? "--" : soldierInfo.PartyTime.ToString("yyyy-MM-dd");
                RankName.Text = soldierInfo.RankName;
                DutyName.Text = soldierInfo.DutyName;        
                JoinPlace.Text = soldierInfo.JoinPlace;           
                Height.Text = soldierInfo.Height == 0 ? "--" : soldierInfo.Height.ToString() + "cm";
                Weight.Text = soldierInfo.Weight == 0.0m ? "--" : soldierInfo.Weight.ToString() + "kg";
                SetUserName.Text = soldierInfo.SetUserName;
                SetTime.Text = soldierInfo.SetTime.ToString("yyyy-MM-dd");
                HomePlace.Text = soldierInfo.HomePlace;
            //    if (soldierInfo.IsDelete)
            //    {
            //      //  btnRestore.Visible = true;
            //        //lblDelete.Visible = true;
            //    }
            //}
            //else
            //{
            //    lblTitle.Text = "您无权查看此兵员信息。";
            //    imgPhoto.ImageUrl = "~/Images/NoPhoto.png";
            //}
        }
    }
    protected void btnRestore_Click(object sender, EventArgs e)
    {
        //Yipusoft.MapInfo.BLL.Cadre soldier = new Yipusoft.MapInfo.BLL.Cadre();
        //SoldierArchiveInfo soldierInfo = soldier.GetSoldierInfoByID(Request["ID"]);
        //if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "203001") ||
        //    Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "400101") ||
        //    ((Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "400102") || Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "203008")) && soldierInfo.DepartmentID.Substring(0, 4) == Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID.Substring(0, 4)) ||
        //    (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "203009") && soldierInfo.DepartmentID == Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID))
        //{
        //    if (soldier.Restore(soldierInfo.SoldierID, User.Identity.Name, Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserName, DateTime.Now))
        //    {
        //        lblDelete.Text = "已恢复。";
        //        btnRestore.Visible = false;
        //    }
        //    else
        //        lblDelete.Text = "恢复失败。";
        //}
        //else
        //{
        //    lblDelete.Text = "权限不足。";
        //    btnRestore.Visible = false;
        //}

    }
}
